<?php
//include("../user/userlogincheck.php");
include("../include/config.inc.php");
include("../api/sms.php");

$day=$_REQUEST["day"];
$dayone = explode(",",$day);
for($x=1;$dayone[$x]<>'';$x++){}
if($x==1){//<span>2017年5月1日</span>
$dayo = explode("<span>",$day);
$d1 = explode("</span>",$dayo[1]);
$orderinfo=$d1[0];
}
elseif($x==2){//<span>2017年5月1日</span>,<span>2017年5月2日</span>
$dayo = explode("</span>,<span>",$day);
$d1 = explode("<span>",$dayo[0]);
$d2 = explode("</span>",$dayo[1]);
$orderinfo=$d1[1].','.$d2[0];
}
elseif($x==3){//<span>2017年5月1日</span>,<span>2017年5月2日</span>,<span>2017年5月3日</span>
$dayo = explode("</span>,<span>",$day);
$d1 = explode("<span>",$dayo[0]);
$d2 = $dayo[1];
$d3 = explode("</span>",$dayo[2]);
$orderinfo=$d1[1].','.$d2.','.$d3[0];
}
elseif($x==4){//<span>2017年5月1日</span>,<span>2017年5月2日</span>,<span>2017年5月3日</span>,<span>2017年5月4日</span>
$dayo = explode("</span>,<span>",$day);
$d1 = explode("<span>",$dayo[0]);
$d2 = $dayo[1];
$d3 = $dayo[2];
$d4 = explode("</span>",$dayo[3]);
$orderinfo=$d1[1].','.$d2.','.$d3.','.$d4[0];
}
else{//<span>2017年5月1日</span>,<span>2017年5月2日</span>,<span>2017年5月3日</span>,<span>2017年5月4日</span>,<span>2017年5月5日</span>
$dayo = explode("</span>,<span>",$day);
$d1 = explode("<span>",$dayo[0]);
$d2 = $dayo[1];
$d3 = $dayo[2];
$d4 = $dayo[3];
$d5 = explode("</span>",$dayo[4]);
$orderinfo=$d1[1].','.$d2.','.$d3.','.$d4.','.$d5[0];
}
$dingjin=1000;
$goods_id=1109;

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){
	$smscode = $_POST['smscode'];
	$code = $_POST['code'];
	$verify = $_SESSION['session_verify'];
	$sms = $_SESSION['session_smscode'];
	if($code==""){
		echo "<script>alert('请输入验证码！');history.back(-1);</script>";
		exit;
	}
	if($code<>$verify){
		echo "<script>alert('请输入正确的验证码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==""){
		echo "<script>alert('请输入手机短信动态码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==$sms){	
		echo "<script>alert('手机短信验证码输入不正确！');history.back(-1);</script>";
		exit;
	}
	$amount=$_POST["amount"];
	$goods_id=$_POST["goods_id"];
	$ordername=$_POST["ordername"];
	$mobile=$_POST["mobile"];
	$payment=$_POST["payment"];
	$orderinfo=$_POST["orderinfo"];	
	$time=time();
	$ip=getIP();
	
	$sql="SELECT id FROM ".tableprefix."order order by id DESC limit 0,1;";
	$result=$db->query($sql);
	$s=$db->fetch_array($result);
	$orderid=$s["id"]+1000001;
	$orderNo='2'.date("ymdHis").$orderid;//业务编码+年的后2位+月+日+订单数(订单ID)[1 170515230101 1000001];
	$sql="insert into ".tableprefix."order(orderNo,userid,amount,goods_id,ordername,mobile,payment,orderinfo,creatertime,ip,paystate)values('$orderNo','$userid','$amount','$goods_id','$ordername','$mobile','$payment','$orderinfo','$time','$ip','0')";
	$db->query($sql);	
	if(!$db->error()){
		$store_id=GetValueByKey(tablepre."goods","goods_id",$goods_id,"store_id");
		$sql="select store_name,member_id from ".tablepre."store where store_id='$store_id'";
		$result=$db->query($sql);
		$row=$db->fetch_array($result);
		$store_name=$row["store_name"];
		$member_id=$row["member_id"];
		$db->free_result($result);
		$member_mobile=GetValueByKey(tablepre."member","member_id",$member_id,"member_mobile");
		$name=$store_name;	
		$content=$orderNo;
		$smstype="placeorder";
		//$sms = new Sms();
		//$result = $sms->Send($member_mobile,$content,$smstype,$name);
		GotoPage('../pay/wxpay/deposit.php?orderNo='.$orderNo);
		exit;	
	}
}
?>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>确认订单</title>
		<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<link rel="stylesheet" type="text/css" href="../css/frameCss/mui.min.css"/>
		<link rel="stylesheet" type="text/css" href="../css/public.css" />
		<link rel="stylesheet" type="text/css" href="../css/store.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
	//function order_save(){
        //$.post('ordersave.php', {mobile:jQuery.trim($('#mobile').val()),send_code:jQuery.trim($('#code').val()),smstype:jQuery.trim($('#smstype').val())});
	//};
</script>
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
	function get_mobile_code(){
        $.post('../user/sms.php', {mobile:jQuery.trim($('#mobile').val()),send_code:jQuery.trim($('#code').val()),smstype:jQuery.trim($('#smstype').val())}, function(msg) {
            alert(jQuery.trim(unescape(msg)));
			if(msg=='短信发送成功'){
				RemainTime();
			}
        });
	};
	var iTime = 59;
	var Account;
	function RemainTime(){
		document.getElementById('zphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取手机验证码';
				iTime = 59;
				document.getElementById('zphone').disabled = false;
			}else{
				Account = setTimeout("RemainTime()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zphone').value = sTime;
	}	
</script>
	</head>

	<body>
		<header></header>
<form id="order-form" action="" method="post">
<input name="todo" type="hidden" value="todo">
<input name="goods_id" type="hidden" id="goods_id" value="<?php echo $goods_id;?>" />
<input name="orderinfo" type="hidden" id="orderinfo" value="<?php echo $orderinfo;?>" />
<input name="smstype" id="smstype" type="hidden" value="mobilecheck">
		<div id="order-container-wrapper">
			<div id="order-container">
				<div class="timeout"></div>
				<div class="playAndDate">
					<div class="playImg">
						<img src="../js/frameJS/iscroll/demos/carousel/leonardo.jpg" />
					</div>
					<ul class="playInfo">
						<li>蒙娜丽莎的微笑</li>
						<li>
						<?php for($x=0;$dayone[$x]<>'';$x++){echo $dayone[$x];}?>
						</li>
						<li>
							<p>已选择<span><?php echo $x;?></span>场，每场订金<span>¥<?php echo $dingjin;?></span>，合计<span>¥<?php echo $x*$dingjin;?></span></p>
						</li>
					</ul>
				</div>
				<div class="clear-1"></div>
				
				<!--
				<div class="address nav_guide">
					<ul>
						<li>
							<dl>
								<dt>联系人：<span style="padding-left: 45px;">网演（13360037291）</span></dt>
								<dd>演出地址：<span>广东省广州市越秀区海山街1号</span></dd>
								<input name="address_id" type="hidden" id="address_id" value="110" />
							</dl>
						</li>
					</ul>
				</div>
				-->
				<div class="orderinfo">
					<div class="order-info">
						<label>联系人</label>
						<input type="text" maxlength="20" id="ordername" name="ordername" placeholder="请填写联系人姓名">
					</div>
					<div class="order-info">
						<label>手机号码</label>
						<input type="text" maxlength="11" id="mobile" name="mobile" placeholder="请填写联系人手机号码">
					</div>
					<div class="order-info">
						<label>验证码</label>
						<input id="code" name="code" type="text" placeholder="请输入验证码" maxlength="4">
			            <span style="position:absolute;top:0px;right:0;width:15%;"><img id="imgCode" src="../include/verify.php" alt="请输入验证码"></span>			
					</div>
					<div class="order-info">
						<label>动态码</label>
						<input type="text" maxlength="6" id="smscode" name="smscode" placeholder="请输入短信验证码">
						<span><input id="zphone" type="button" value=" 获取手机验证码 " onClick="get_mobile_code();" class="btn"></span>
					</div>
				</div>
							
				<div class="payWay">
					<p>请选择支付方式</p>
					<div class="wechatPay mui-radio">
						<input type="radio" name="payment" id="payment" value="wechatPay" checked>
						<img src="../images/wechatPay.jpg" />
						<label for="optionsRadios1">微信</label>
					</div>
					<div class="aliPay mui-radio">
						<input type="radio" name="payment" id="payment" value="aliPay">
						<img src="../images/AliPay.jpg" />
						<label for="optionsRadios2">支付宝</label>
					</div>
				</div>
				<div class="mui-input-group">
					<div class="mui-input-row mui-checkbox mui-left" style="height: 50px;">
						<span style="line-height: 50px;margin-left: 15%;">我已仔细阅读<button class="mui-btn mui-btn-blue mui-btn-outlined" style="float: none;width: 25%;margin: 9px 0 0 5px;padding: 8px 15px;" data-toggle="modal" data-target="#myModal">相关条例</button></span>
						<input name="checkbox" value="Item 1" type="checkbox" style="top: 7px;left: 0;margin-left: 5%;" checked>
					</div>
				</div>
			</div>
		</div>
		<div id="confirmPay">
			<p>需支付：<span style="color: #FF0000;"><span style="font-size: 24px;">5000</span>元</span>
			</p>
			<div><input name="amount" type="hidden" id="amount" value="<?php echo $x*$dingjin;?>" /><input name="s" type="submit" class="confirmBtn btn btn-danger btn-lg" value="提交订单" /></div>
		</div>
		
		<!-- 相关条例弹出框 -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document" style="margin-top: 40%;">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">Modal title</h4>
					</div>
					<div class="modal-body">
						...
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary" data-dismiss="modal">阅读完毕</button>
					</div>
				</div>
			</div>
		</div>
</form>
		<script src="../js/frameJS/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/frameJS/iscroll/build/iscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/frameJS/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
		<script type="text/javascript">
			$(function() {
				//加载公共头部！！！
				$('header').load('../commonTemplate/common-header.html')

				//引用iScroll并调用
				function loaded() {
					var myScroll = new IScroll('#order-container-wrapper', {
						scrollbars: false,
						mouseWheel: true,
						interactiveScrollbars: true,
						shrinkScrollbars: 'scale',
						fadeScrollbars: true
					});
				}
				window.setTimeout(loaded, 100);
				
				//支付剩余时间倒数
				function reciprocal() {
					var m = 29;
					var s = 59;
					setInterval(function() {
						if(s < 10) {
							$('#order-container-wrapper .time').html(m + ':0' + s);
						} else {
							$('#order-container-wrapper .time').html(m + ':' + s);
						}
						s--;
						if(s < 0) {
							s = 59;
							m--;
						}
					}, 1000)

					$('#order-container-wrapper .timeout').html('支付剩余时间：<span class="time"></span>')
				}
				reciprocal();
				
				//点击地址跳转到地址页
				function toAddress(){
					$('.address li').click(function(){
						window.location.href = '../user/address.html'
					})
				}
				toAddress();
			})
		</script>
	</body>

</html>